<?
class Youtube {
	var $link;
	var $id;

	function load($link){
		$this->link = $link;

		if(strstr($link, "youtu.be")){
			$tmp = explode("/",$link);
			$this->id = end($tmp);
		}elseif(strstr($link, "youtube")){
			parse_str( parse_url( $link, PHP_URL_QUERY ), $avar );
			$this->id = $avar['v'];
		}else{
			$this->id = $link;
		}
	}

	function getYoutubeID(){
		return $this->id;
	}

	function getImage(){
		return "http://img.youtube.com/vi/".$this->id."/mqdefault.jpg";
	}

	function getDesc(){
		$url = "http://gdata.youtube.com/feeds/api/videos/". $this->id;
		$doc = new DOMDocument;
		$doc->load($url);

		$desc['title'] = $doc->getElementsByTagName("title")->item(0)->nodeValue;
		$desc['name'] = $doc->getElementsByTagName("name")->item(0)->nodeValue;
		$desc['link'] = "http://www.youtube.com/embed/".$this->id;

		return $desc;
	}
}
?>